package assignment;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 
 * @author 86136
 * 2.（必做）思考有多少种方式，在 main 函数启动一个新线程，运行一个方法，拿到这
 * 个方法的返回值后，退出主线程? 写出你的方法，越多越好，提交到 GitHub。
 */
public class HomeworkCallable {
	
	public static void main(String [] args) throws InterruptedException, ExecutionException {
		ExecutorService es = Executors.newFixedThreadPool(1);
		long start = System.currentTimeMillis();
		Future<Integer> future = es.submit(new Callable<Integer>() {
			public Integer call() throws Exception {
				return sum();
			}
			
		});
		int result = future.get();
		System.out.println("result==>" + result);
		System.out.println("Use mills==>"+(System.currentTimeMillis()-start));
	}
	
	public static int sum() {
		return fibo(36);
	}
	
	public static int fibo(int a) {
		if(a<2)
			return 1;
		return fibo(a-1)+fibo(a-2);
	}
}
